package com.summer.safe.quartz.controller;

import com.summer.safe.quartz.service.QuartzLogService;
import com.summer.safe.base.BaseController;
import com.summer.safe.base.Page;
import com.summer.safe.config.annotation.ResultWrapper;
import com.summer.safe.config.result.ResultCode;
import com.summer.safe.quartz.entity.QuartzLog;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 任务调度日志Controller
 *
 * @author lm
 * @date 2020-07-29 17:13:20
 */
@Controller
@RequestMapping(value = "/quartz/quartzLog")
public class QuartzLogController extends BaseController {
    private String PREFIX = "/quartz/";

    @Autowired
    private QuartzLogService quartzLogService;

    @ModelAttribute("quartzLog")
    public QuartzLog get(@RequestParam(required=false) String id) {
        if (StringUtils.isNotBlank(id)){
            return quartzLogService.get(id);
        }else{
            return new QuartzLog();
        }
    }

    /**
     * 列表页面的跳转
     *
     * @author lm
     * @date 2020-07-29 17:13:20
     */
    @RequiresPermissions("quartz:quartzLog:view")
    @GetMapping("")
    public String index() {
        return PREFIX + "quartzLogList.html";
    }

    /**
     * 获取列表数据
     *
     * @author lm
     * @date 2020-07-29 17:13:20
     */
    @GetMapping("/dataList")
    @ResultWrapper(ResultCode.SUCCESS_QUERY)
    public Page list(QuartzLog quartzLog, HttpServletRequest request) {
        Page<QuartzLog> page = quartzLogService.findPage(new Page(request), quartzLog);
        return page;
    }
    /**
     * 表单页面的跳转
     *
     * @author lm
     * @date 2020-07-29 17:13:20
     */
    @GetMapping("/form")
    @RequiresPermissions("quartz:quartzLog:edit")
    public String form(QuartzLog quartzLog, Model model) {
        model.addAttribute("quartzLog", quartzLog);
        return PREFIX + "quartzLogForm.html";
    }




    /**
     * 提交数据
     *
     *@author lm
     * @date 2020-07-29 17:13:20
     */
    @PostMapping("/save")
    @ResultWrapper(ResultCode.SUCCESS_SAVE)
    public void save(QuartzLog quartzLog) {
        quartzLogService.save(quartzLog);
    }
    /**
     * 删除数据
     *
     *@author lm
     * @date 2020-07-29 17:13:20
     */
    @PostMapping("/delete")
    @ResultWrapper(ResultCode.SUCCESS_DELETE)
    public void delete(QuartzLog quartzLog) {
        quartzLogService.delete(quartzLog);
    }
}